﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Xml;
using System.Web;

namespace ArticleDean.web.Service
{
    // NOTE: If you change the class name "WSDataService" here, you must also update the reference to "WSDataService" in Web.config.
    public class WSDataServiceSVC : IWSDataService
    {
        public string GetStatesInJson()
        {
            StringBuilder sbStates = new StringBuilder();

            XmlDocument doc = new XmlDocument();
            doc.Load(HttpContext.Current.Server.MapPath("~/Data/States.xml"));
            try
            {
                foreach (XmlElement xnl in doc.DocumentElement.ChildNodes)
                {
                    sbStates.AppendFormat("{0}:", xnl.Attributes["name"].Value);
                }

                sbStates = sbStates.Remove(sbStates.Length - 1, 1); //Removes the extra ":"
            }
            catch (Exception ex)
            {
                string exp = ex.ToString(); //Setup a breakpoint here to verify any exceptions raised.
            }
            return sbStates.ToString();
        }
    }
}
